package cn.calm.swing.osgi.mysql.blance.ui;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class JTableJCheckBoxRenderer implements TableCellRenderer, ActionListener {

	/**
	 * 
	 */
	private JCheckBox box = new JCheckBox();

	public JTableJCheckBoxRenderer() {
		box.addActionListener(this);
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		if (column == 2) {
			box.setSelected(Boolean.valueOf(String.valueOf(value)));

			return box;
		}
		return box;

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		box.setSelected(!box.isSelected());
	}
}
